package com.heima.wemedia.controller.v1;

import com.heima.common.exception.CustomException;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {

    @Autowired
    private WmMaterialService wmMaterialService;

    /**
     * 上传图片
     * @param file
     * @return
     */
    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(@RequestParam("multipartFile") MultipartFile file){
        if(file.isEmpty()){
            throw new CustomException(AppHttpCodeEnum.PARAM_INVALID,"文件不能为空");
        }
        return ResponseResult.okResult(wmMaterialService.uploadPicture(file));
    }

    /**
     * 素材列表查询
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmMaterialDto dto){
        return wmMaterialService.findPage(dto);
    }
}
